<?php
/**
 * ****************************************************************************
 *  - TDMDownloads By TDM   - TEAM DEV MODULE FOR XOOPS
 *  - GNU Licence Copyright (c)  (www.xoops.org)
 *
 * La licence GNU GPL, garanti à l'utilisateur les droits suivants
 *
 * 1. La liberté d'exécuter le logiciel, pour n'importe quel usage,
 * 2. La liberté de l' étudier et de l'adapter à ses besoins,
 * 3. La liberté de redistribuer des copies,
 * 4. La liberté d'améliorer et de rendre publiques les modifications afin
 * que l'ensemble de la communauté en bénéficie.
 *
 * @copyright   http://www.tdmxoops.net
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
 * @author		TDM (G.Mage); TEAM DEV MODULE
 *
 * ****************************************************************************
 */

function tdmdownloads_adminmenu ($currentoption = 0, $breadcrumb = '') {      
		
	/* Nice buttons styles */
	echo "
    	<style type='text/css'>
    	#buttontop { float:left; width:100%; background: #e7e7e7; font-size:93%; line-height:normal; border-top: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; margin: 0; }
    	#buttonbar { float:left; width:100%; background: #e7e7e7 url('" . XOOPS_URL . "/modules/TDMDownloads/images/deco/bg.png') repeat-x left bottom; font-size:93%; line-height:normal; border-left: 1px solid black; border-right: 1px solid black; margin-bottom: 12px; }
    	#buttonbar ul { margin:0; margin-top: 15px; padding:10px 10px 0; list-style:none; }
		#buttonbar li { display:inline; margin:0; padding:0; }
		#buttonbar a { float:left; background:url('" . XOOPS_URL . "/modules/TDMDownloads/images/deco/left_both.png') no-repeat left top; margin:0; padding:0 0 0 9px; border-bottom:1px solid #000; text-decoration:none; }
		#buttonbar a span { float:left; display:block; background:url('" . XOOPS_URL . "/modules/TDMDownloads/images/deco/right_both.png') no-repeat right top; padding:5px 15px 4px 6px; font-weight:bold; color:#765; }
		/* Commented Backslash Hack hides rule from IE5-Mac \*/
		#buttonbar a span {float:none;}
		/* End IE5-Mac hack */
		#buttonbar a:hover span { color:#333; }
		#buttonbar #current a { background-position:0 -150px; border-width:0; }
		#buttonbar #current a span { background-position:100% -150px; padding-bottom:5px; color:#333; }
		#buttonbar a:hover { background-position:0% -150px; }
		#buttonbar a:hover span { background-position:100% -150px; }
		</style>
    ";
	
	global $xoopsModule, $xoopsConfig;
	
	$tblColors = Array();
	$tblColors[0] = $tblColors[1] = $tblColors[2] = $tblColors[3] = $tblColors[4] = $tblColors[5] = $tblColors[6] = $tblColors[7] = $tblColors[8] = '';
	$tblColors[$currentoption] = 'current';
	if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) {
		include_once XOOPS_ROOT_PATH . '/modules/TDMDownloads/language/' . $xoopsConfig['language'] . '/modinfo.php';
	} else {
		include_once XOOPS_ROOT_PATH . '/modules/TDMDownloads/english/modinfo.php';
	}
	
	echo "<div id='buttontop'>";
	echo "<table style=\"width: 100%; padding: 0; \" cellspacing=\"0\"><tr>";
	//echo "<td style=\"width: 45%; font-size: 10px; text-align: left; color: #2F5376; padding: 0 6px; line-height: 18px;\"><a class=\"nobutton\" href=\"../../system/admin.php?fct=preferences&amp;op=showmod&amp;mod=" . $xoopsModule->getVar('mid') . "\">" . _AM_SF_OPTS . "</a> | <a href=\"import.php\">" . _AM_SF_IMPORT . "</a> | <a href=\"../index.php\">" . _AM_SF_GOMOD . "</a> | <a href=\"../help/index.html\" target=\"_blank\">" . _AM_SF_HELP . "</a> | <a href=\"about.php\">" . _AM_SF_ABOUT . "</a></td>";
	echo "<td style='font-size: 10px; text-align: left; color: #2F5376; padding: 0 6px; line-height: 18px;'>
	  <a class='nobutton' href='" . XOOPS_URL . "/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=" . $xoopsModule->getVar('mid') . "'>" . _PREFERENCES . "</a> 
	| <a href='" . XOOPS_URL . "/modules/TDMDownloads/index.php'>" . $GLOBALS["xoopsModule"]->getVar("name") . "</a>
	</td>";
	echo "<td style='font-size: 10px; text-align: right; color: #2F5376; padding: 0 6px; line-height: 18px;'><b>" . $xoopsModule->name() . " </b> </td>";
	echo "</tr></table>";
	echo "</div>";
	
	echo "<div id='buttonbar'>";
	echo "<ul>";
       echo "<li id='" . $tblColors[0] . "'><a href=\"" . XOOPS_URL . "/modules/TDMDownloads/admin/index.php\"><span>" . _MI_TDMDOWNLOADS_ADMENU1 . "</span></a></li>";
	echo "<li id='" . $tblColors[1] . "'><a href=\"" . XOOPS_URL . "/modules/TDMDownloads/admin/category.php\"><span>" . _MI_TDMDOWNLOADS_ADMENU2 . "</span></a></li>";
	echo "<li id='" . $tblColors[2] . "'><a href=\"" . XOOPS_URL . "/modules/TDMDownloads/admin/downloads.php\"><span>" . _MI_TDMDOWNLOADS_ADMENU3 . "</span></a></li>";
"</span></a></li>";
	echo "<li id='" . $tblColors[3] . "'><a href=\"" . XOOPS_URL . "/modules/TDMDownloads/admin/broken.php\"><span>" . _MI_TDMDOWNLOADS_ADMENU4 . "</span></a></li>";
	echo "<li id='" . $tblColors[4] . "'><a href=\"" . XOOPS_URL . "/modules/TDMDownloads/admin/modified.php\"><span>" . _MI_TDMDOWNLOADS_ADMENU5 . "</span></a></li>";
	echo "<li id='" . $tblColors[5] . "'><a href=\"" . XOOPS_URL . "/modules/TDMDownloads/admin/champs.php\"><span>" . _MI_TDMDOWNLOADS_ADMENU6 . "</span></a></li>";
	echo "<li id='" . $tblColors[6] . "'><a href=\"" . XOOPS_URL . "/modules/TDMDownloads/admin/permissions.php\"><span>" . _MI_TDMDOWNLOADS_ADMENU7 . "</span></a></li>";
	echo "</ul></div>&nbsp;";
}

// fonction qui permet d'afficher les catégories enfants
function tdmdownloads_display_childrentree ($cid = 0, $cat_arr, $prefix = '', $sufix = '', $order = '', &$class) {
    //paramètres:
    // pour les images des catégories:
    $uploaddir = XOOPS_ROOT_PATH . '/uploads/TDMDownloads/images/cats/';
    $uploadurl = XOOPS_URL . '/uploads/TDMDownloads/images/cats/';
    /////////////
    $downloadscat_Handler =& xoops_getModuleHandler('tdmdownloads_cat', 'TDMDownloads');    
    $prefix = $prefix . '--';
    $sufix = $sufix . '';
    foreach (array_keys($cat_arr) as $i) {
        $downloadscat_cid = $cat_arr[$i]->getVar('cid');
        echo '<tr class="'.$class.'">';
        echo '<td align="left">' . $prefix . '<a href="' . XOOPS_URL . '/modules/TDMDownloads/viewcat.php?cid=' . $downloadscat_cid . '">' . $cat_arr[$i]->getVar('title') . $sufix . '</a></td>';
        echo '<td align="center" width="10%">';
        echo '<img src="' . $uploadurl . $cat_arr[$i]->getVar('imgurl') . '" alt="" title="" height="60">';
        echo '</td>';
        echo '<td align="center" width="5%">' . $cat_arr[$i]->getVar('weight') . '</td>';
        echo '<td align="center" width="10%">';
        echo '<a href="category.php?op=view_cat&downloadscat_cid=' . $downloadscat_cid . '"><img src="../images/icon/view_mini.png" alt="'._AM_TDMDOWNLOADS_FORMDISPLAY.'" title="'._AM_TDMDOWNLOADS_FORMDISPLAY.'"></a> ';
        echo '<a href="category.php?op=edit_cat&downloadscat_cid=' . $downloadscat_cid . '"><img src="../images/icon/edit_mini.gif" alt="'._AM_TDMDOWNLOADS_FORMEDIT.'" title="'._AM_TDMDOWNLOADS_FORMEDIT.'"></a> ';
        echo '<a href="category.php?op=del_cat&downloadscat_cid=' . $downloadscat_cid . '"><img src="../images/icon/delete_mini.gif" alt="'._AM_TDMDOWNLOADS_FORMDEL.'" title="'._AM_TDMDOWNLOADS_FORMDEL.'"></a>';
        echo '</td>';        
        echo '</tr>';
        $class = ($class == 'even') ? 'odd' : 'even';
        $criteria = new CriteriaCompo();
        $criteria->add(new Criteria('pid', $cat_arr[$i]->getVar('cid')));
        $criteria->setSort($order);
        $criteria->setOrder('ASC');
        $tdmdownloads_catchildren = $downloadscat_Handler->getall($criteria);
        if (count($tdmdownloads_catchildren) != 0){
            tdmdownloads_display_childrentree($cat_arr[$i]->getVar('cid'),$tdmdownloads_catchildren, $prefix, $sufix, $order, $class);
        }
    }
}

//Mise à jour
function moduleLastVersionInfo($version, $module_name) 
{
	//Version du module installé
    $raw = '';
	$version_en_cours = substr($version,0,1).'.'.substr($version,1,1);
	$site_xml = "http://tdmxoops.net/TDM_Modules_Version.xml";
    if(ini_get('allow_url_fopen')) {
        $fp = @fopen($site_xml,"r");
        if (!$fp){
            echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_TDMDOWNLOADS_INDEX_UPDATE_INFO . '</legend>';
            echo "<span style=\"color:red;\">" . _AM_TDMDOWNLOADS_INDEX_VERSION_FICHIER_KO . "</span>";
            echo '</fieldset><br /><br />';
        }else{
            while(!feof($fp)) $raw .= @fgets($fp, 4096);
            fclose($fp);
            if( @eregi("<module>(.*)</module>", $raw, $rawelements ) ) 
            {
                $elements = explode("<module>", $rawelements[0]);
                $maximum = count($elements);
                for( $i=1; $i<$maximum; $i++ ) 
                {
                    @eregi( "<name>(.*)</name>",$elements[$i], $name );
                    @eregi( "<version>(.*)</version>",$elements[$i], $version );
                    @eregi( "<xoopsVersionNeeded>(.*)</xoopsVersionNeeded>",$elements[$i], $xoopsVersionNeeded );
                    @eregi( "<versionChangelog>(.*)</versionChangelog>",$elements[$i], $versionChangelog );			
                    if( $name[1] == $module_name )
                    {
                        $infos_module[0] = $name[1];
                        $infos_module[1] = $version[1];
                        $infos_module[2] = $xoopsVersionNeeded[1];
                        $infos_module[3] = utf8_encode($versionChangelog[1]);
                    } 
                }		
            }
            echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_TDMDOWNLOADS_INDEX_UPDATE_INFO . '</legend>';
            if( $version_en_cours == $infos_module[1] ) {
                echo "<span style=\"color:green; \">" . sprintf(_AM_TDMDOWNLOADS_INDEX_VERSION_OK, $infos_module[1]) . "</span>";
            } else {
                echo "<span style=\"color:red;\">" . sprintf(_AM_TDMDOWNLOADS_INDEX_VERSION_NOT_OK, $infos_module[1]) . "</span>";
                echo '<br /><br />' . _AM_TDMDOWNLOADS_INDEX_CHANGELOG . '<br />' . $infos_module[3];
            }
            echo '</fieldset><br /><br />';
        }
    }else{
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_TDMDOWNLOADS_INDEX_UPDATE_INFO . '</legend>';
        echo "<span style=\"color:red;\">" . _AM_TDMDOWNLOADS_INDEX_VERSION_ALLOWURLFOPEN . "</span>";
        echo '</fieldset><br /><br />';
    }
}
?>